From 685a0f7ca6c246bfa4ccd281a9d47542f2827722 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Mon, 28 Apr 2014 23:36:04 +0200 Subject: [PATCH] extend conversions to n_components to pad with 0s Test coverage updated to check these cases. --- babl/babl-fish-reference.c | 51 +++++++++++--------------------------- tests/n_components_cast.c | 41 ++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 41 deletions(-) diff --git a/babl/babl-fish-reference.c b/babl/babl-fish-reference.c index 6d0f270..4133e40 100644 --- a/babl/babl-fish-reference.c +++ b/babl/babl-fish-reference.c @@ -218,7 +218,7 @@ ncomponent_convert_to_double (BablFormat *source_fmt, dst_img->pitch[0] = (dst_img->type[0]->bits / 8); dst_img->stride[0] = 0; - src_img->data[0] = source_buf; + src_img->data[0] = source_buf; src_img->type[0] = source_fmt->type[0]; src_img->pitch[0] = source_fmt->type[0]->bits / 8; src_img->stride[0] = 0; @@ -271,25 +271,24 @@ ncomponent_convert_from_double (BablFormat *destination_fmt, static int -process_same_model2 (const Babl *babl, - const char *source, - char *destination, - long n) +process_to_n_component (const Babl *babl, + const char *source, + char *destination, + long n) { void *double_buf; - +#ifndef MAX #define MAX(a, b) ((a) > (b) ? (a) : (b)) +#endif + int components = MAX(BABL (babl->fish.source)->format.model->components, + BABL (babl->fish.source)->format.components); + components = MAX(components, BABL (babl->fish.destination)->format.components); + components = MAX(components, BABL (babl->fish.destination)->model.components); - double_buf = babl_malloc (sizeof (double) * n * - MAX (BABL (babl->fish.source)->format.model->components, - BABL (babl->fish.source)->format.components)); -#undef MAX + double_buf = babl_malloc (sizeof (double) * n * components); + memset (double_buf, 0,sizeof (double) * n * components); - if (1) { - /* FIXME: should recursively invoke babl and look up an appropriate fish - * for the conversion and multiply n by the number of components. - */ ncomponent_convert_to_double ( (BablFormat *) BABL (babl->fish.source), (char *) source, @@ -304,22 +303,7 @@ process_same_model2 (const Babl *babl, n ); } - else - { - convert_to_double ( - (BablFormat *) BABL (babl->fish.source), - (char *) source, - double_buf, - n - ); - convert_from_double ( - (BablFormat *) BABL (babl->fish.destination), - double_buf, - (char *) destination, - n - ); - } babl_free (double_buf); return 0; } @@ -332,7 +316,6 @@ process_same_model (const Babl *babl, long n) { void *double_buf; - #define MAX(a, b) ((a) > (b) ? (a) : (b)) double_buf = babl_malloc (sizeof (double) * n * @@ -340,15 +323,11 @@ process_same_model (const Babl *babl, BABL (babl->fish.source)->format.components)); #undef MAX - if ( - (BABL (babl->fish.source)->format.components == + if ((BABL (babl->fish.source)->format.components == BABL (babl->fish.destination)->format.components) && (BABL (babl->fish.source)->format.model->components != BABL (babl->fish.source)->format.components)) { - /* FIXME: should recursively invoke babl and look up an appropriate fish - * for the conversion and multiply n by the number of components. - */ ncomponent_convert_to_double ( (BablFormat *) BABL (babl->fish.source), (char *) source, @@ -403,7 +382,7 @@ babl_fish_reference_process (const Babl *babl, if (babl_format_is_format_n (BABL (babl->fish.destination))) { - return process_same_model2 (babl, source, destination, n); + return process_to_n_component (babl, source, destination, n); } diff --git a/tests/n_components_cast.c b/tests/n_components_cast.c index 307431a..4bb7d29 100644 --- a/tests/n_components_cast.c +++ b/tests/n_components_cast.c @@ -34,31 +34,62 @@ main (int argc, unsigned char out1[][1] = {{0}, {4}, {8} }; unsigned char out2[][2] = {{0,1}, {4,5}, {8,9} }; unsigned char out4[][4] = {{0,1,2,3}, {4,5,6,7}, {8,9,10,11} }; - //unsigned char out5[][5] = {{0,1,2,3,0}, {4,5,6,7,0},{8,9,10,11,0} }; + unsigned char out5[][5] = {{0,1,2,3,0}, {4,5,6,7,0},{8,9,10,11,0} }; CHECK_CONV("RGBAu8 to n1'", unsigned char, babl_format("R'G'B'A u8"), babl_format_n (babl_type ("u8"), 1), in, out1); - CHECK_CONV("RGBAu8 to n2'", unsigned char, babl_format("R'G'B'A u8"), babl_format_n (babl_type ("u8"), 2), in, out2); - CHECK_CONV("RGBAu8 to n4'", unsigned char, babl_format("R'G'B'A u8"), babl_format_n (babl_type ("u8"), 4), in, out4); - /* XXX: uncomment this when it passes CHECK_CONV("RGBAu8 to n5'", unsigned char, babl_format("R'G'B'A u8"), babl_format_n (babl_type ("u8"), 5), in, out5); - */ + } + { + unsigned char in[][3] = {{0,1,2 },{4,5,6 },{8,9,10 }}; + unsigned char out1[][1] = {{0}, {4}, {8} }; + unsigned char out2[][2] = {{0,1}, {4,5}, {8,9} }; + unsigned char out4[][4] = {{0,1,2,0}, {4,5,6,0}, {8,9,10,0} }; + unsigned char out5[][5] = {{0,1,2,0,0}, {4,5,6,0,0},{8,9,10,0,0} }; + unsigned char out6[][6] = {{0,1,2,0,0,0}, {4,5,6,0,0,0},{8,9,10,0,0,0} }; + + CHECK_CONV("RGBu8 to n1'", unsigned char, + babl_format("R'G'B' u8"), + babl_format_n (babl_type ("u8"), 1), + in, out1); + + + CHECK_CONV("RGBu8 to n2'", unsigned char, + babl_format("R'G'B' u8"), + babl_format_n (babl_type ("u8"), 2), + in, out2); + + + CHECK_CONV("RGBu8 to n4'", unsigned char, + babl_format("R'G'B' u8"), + babl_format_n (babl_type ("u8"), 4), + in, out4); + + CHECK_CONV("RGBu8 to n5'", unsigned char, + babl_format("R'G'B' u8"), + babl_format_n (babl_type ("u8"), 5), + in, out5); + + CHECK_CONV("RGBu8 to n6'", unsigned char, + babl_format("R'G'B' u8"), + babl_format_n (babl_type ("u8"), 6), + in, out6); } babl_exit (); -- 2.30.2